package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

//分页查询所有和条件查询
@RestController
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @GetMapping("/setmeal/page")
    public ResultInfo findByName(@RequestParam(value = "page",defaultValue = "1") Integer pageNum,
                                 @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize
                                 , String name){//接收参数
        //调用service
        Page<Setmeal> list=setmealService.findByName(pageNum,pageSize,name);
        //返回结果
        return ResultInfo.success(list);

    }
    // 菜品删除
    @DeleteMapping("/setmeal")
    public ResultInfo deleteBatchIds(@RequestParam List<Long> ids){ // 1.接收参数
        // 2.调用service
        setmealService.deleteBatchIds(ids);
        // 3.返回成功
        return ResultInfo.success();
    }
    //修改回显
    @GetMapping("/setmeal/{id}")
    public ResultInfo findById(@PathVariable("id") Long id) {
        //调用service查询
        Setmeal setmeal = setmealService.findById(id);
        //返回结果
        return ResultInfo.success(setmeal);

    }
    //修改套餐
    @PutMapping("/setmeal")
    public ResultInfo update(@RequestBody Setmeal setmeal){//接收参数
        //调用service
        setmealService.update(setmeal);
        //返回结果
        return ResultInfo.success();

    }
    // 启停售
    @PostMapping("/setmeal/status/{type}")
    public ResultInfo sellStatus(@PathVariable("type")Integer type,@RequestParam List<Long> ids){//接收参数
        //调用service
        setmealService.sellStatus(type,ids);
        //返回结果
        return ResultInfo.success();
    }
}